package com.feng.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.feng.dao.IJournalDao;
import com.feng.dao.IJournalDetailDao;
import com.feng.entity.Journal;
import com.feng.entity.JournalDetail;
import com.feng.service.IJournalService;
import com.feng.util.PageUtil;
@Service
public class JournalServiceImpl implements IJournalService {

	@Autowired
	private IJournalDao journalDao;
	@Autowired
	private IJournalDetailDao journalDetailDao;
	@Override
	public List<Journal> findAll() throws Exception {
		return journalDao.findJournals();
	}
	@Override
	public List<Journal> findByWhere(Journal vo) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Journal findJournalById(String id) throws Exception {
		return journalDao.findJournalById(id);
	}
	@Override
	public List<JournalDetail> findJournalDetailsByJournalId(String id) throws Exception {
		return journalDetailDao.findJournalDetailsByJournalId(id);
	}
	@Override
	public List<Journal> findWorkJournals() throws Exception {
		return journalDao.findJournalsByType("1");
	}
	@Override
	public List<Journal> findJournalsByType(String type) {
		return journalDao.findJournalsByType(type);
	}
	@Override
	public PageUtil<Journal> findJournalsByTypePage(String type,Integer pageNum) {
		PageUtil<Journal> vo=new PageUtil<Journal>();
		vo.setType(type);
		List<Journal> list=journalDao.findJournalsByType(type);
		if(list!=null){
			vo.setTotalDataCount(list.size());
			vo.setPageNum(pageNum==null?1:pageNum);
			vo.initTotalPageCount();
		}
		vo.setList(journalDao.findJournalsByTypePage(vo));
		return vo;
	}
	@Override
	public int saveJournal(Journal journal) {
		return journalDao.saveJournal(journal);
	}
	@Override
	public int deleteJournalInfo(String id) {
		int i=0;
		if(!"".equals(id)){
			i=journalDao.deleteJournalById(id);
			journalDetailDao.deleteJournalDetailByJournalId(id);
		}
		return i;
	}
	@Override
	public int saveJournalDetail(JournalDetail journalDetail) throws Exception {
		return journalDetailDao.insertJournalDetail(journalDetail);
	}
	@Override
	public int deleteJournalDetail(String id) {
		return journalDetailDao.deleteJournalDetailById(id);
	}

}
